package com.itheima.servlet;

import com.itheima.bean.Student;
import com.itheima.dao.ListStudent;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/listStudentServlet")
public class ListStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      //  resp.setContentType("text/html;charset=UTF-8 ");
        BufferedReader br = new BufferedReader(new FileReader("e:\\stu.txt"));
        ArrayList<Student> list = new ArrayList<>();
//创建一个list集合用来保存数据
        ListStudent ls=new ListStudent();
        ls.listStudent(br,list);
       // System.out.println(list);
//遍历集合，响应给浏览器
       req.getSession().setAttribute("stu",list);
        resp.sendRedirect("/stu/listStudent.jsp");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
